<?php

namespace app\admin\model\shopro\cats;

use think\Model;


class Cats extends Model
{

    // 表名
    protected $name = 'shopro_cats';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'gender_text',
        'status_text'
    ];

    public function getBreedList()
    {
        $breed = new Breed();
        return $breed->where(['status'=>1])->field('id,name')->select();
    }
    
    public function getGenderList()
    {
        return ['1' => __('公猫'), '2' => __('母猫')];
    }

    public function getStatusList()
    {
        return ['0' => __('隐藏'), '1' => __('正常')];
    }


    public function getGenderTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['gender']) ? $data['gender'] : '');
        $list = $this->getGenderList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    //喵咪关联品种
    public function breeds()
    {
        return $this->hasOne(Breed::class,"id","pid")->setEagerlyType(0);
    }


}
